package com.atguigu.gmall.realtime.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @author Archie
 * @date 2021-10-26 9:33
 * @description
 */
public class RedisUtil {

	private static JedisPool pool;

	static {
		JedisPoolConfig conf = new JedisPoolConfig();
		conf.setMaxTotal(300); // 连接池客户端数量
		conf.setMaxIdle(100); // 允许的最大空闲连接数
		conf.setMinIdle(10); // 允许最小的空闲连接数
		conf.setTestOnCreate(true); // 连接前置自测
		conf.setTestOnBorrow(true); // 连接前置自测
		conf.setTestOnReturn(true); // 连接前置自测
		conf.setMaxWaitMillis(10000); // 最大等待时长 10s
		pool = new JedisPool(conf, "hadoop101", 6379);
	}

	public static Jedis getClient() {
		Jedis client = pool.getResource();
		client.select(1);
		return client;
	}

}
